const Mock = require('mockjs')

const List = []
const count = 4
// const List = {
//   "data|10-20": [
//     {
//       "petType_id": '@increment',
//       "petType_name": '@cword(2)'
//     }
//   ]
// }
for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    petType_id: '@increment',
    petType_name: '@cword(2)'
  }))
}

module.exports = [
  {
    url: '/petType/selectAll',
    type: 'get',
    response: config => {
      return { code: 20000, msg: '查询成功', data: List }
    }
  },
  {
    url: '/petType/add',
    type: 'get',
    response: config => {
      List.unshift(config.query)
      console.log(List)
      return { code: 20000, msg: '新增成功', data: List }
    }
  },
  {
    url: '/petType/update',
    type: 'get',
    response: config => {
      const index = List.findIndex(v => v.petType_id == config.query.petType_id)
      List.splice(index, 1, config.query)
      console.log(List)
      return { code: 20000, msg: '修改成功', data: List }
    }
  },
  {
    url: '/petType/del',
    type: 'get',
    response: config => {
      console.log(config.query.id)
      const index = List.findIndex(v => v.petType_id === config.query.id)
      List.splice(index, 1)
      console.log(List)
      return { code: 20000, msg: '删除成功', data: List }
    }
  },
  {
    url: '/petType/searchbyname',
    type: 'get',
    response: config => {
      console.log(config.query.name)
      const newList = List.filter(v => {
        if (v.petType_name == config.query.name) {
          return v;
        }
      })
      console.log(newList)
      return { code: 20000, msg: '查询类型成功', data: newList }
    }
  },
]